import java.util.ArrayList;
import java.util.List;

class UnionFind {
    private int[] parent;
    private List<List<String>> permissions;

    public UnionFind(int n) {
        parent = new int[n];
        permissions = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
            permissions.add(new ArrayList<>());
        }
    }

    public void union(int u, int v) {
        parent[find(u)] = find(v);
    }

    public int find(int u) {
        if (parent[u] != u) {
            parent[u] = find(parent[u]);
        }
        return parent[u];
    }

    public void setPermissions(int u, List<String> permissionList) {
        permissions.set(u, permissionList);
    }

    public boolean checkPermission(int u, String permission) {
        int root = find(u);
        List<String> permissionList = permissions.get(root);
        return permissionList.contains(permission);
    }
}

public class Main {
    public static void main(String[] args) {
        int n = 10; // 假设有10个用户或资源
        UnionFind uf = new UnionFind(n);

        // 授权用户 1 和 2 具有权限 ['read', 'write']
        List<String> permissions1 = new ArrayList<>();
        permissions1.add("read");
        permissions1.add("write");
        uf.setPermissions(1, permissions1);

        List<String> permissions2 = new ArrayList<>();
        permissions2.add("read");
        permissions2.add("write");
        uf.setPermissions(2, permissions2);

        // 合并用户 1 和 2 的集合
        uf.union(1, 2);

        // 检查用户 1 和 2 是否具有权限 'read'
        System.out.println(uf.checkPermission(1, "read")); // 输出: true
        System.out.println(uf.checkPermission(2, "read")); // 输出: true

        // 检查用户 1 和 2 是否具有权限 'execute'
        System.out.println(uf.checkPermission(1, "execute")); // 输出: false
        System.out.println(uf.checkPermission(2, "execute")); // 输出: false
    }
}
